Chapter 3
 The Grand Tour: 
 Application Builder
 t Your First Application
 t Adding a Menu
 t Adding a Window
 t Creating Methods during Runtime
 t A Persistent Database and
 Local Methods
 t Adding a Scrolling List to a Window
 t Your First Prograph Challenge
 t The Journey’s End

During the Grand Tour of the Application Builder*50* you:

q use the Prograph Application Builder to develop your first application

q challenge your understanding of Prograph with activities to extend your first application.

t
Your First Application

In chapter 2, “The Grand Tour: Language,” you created your first Prograph class and methods. Your methods*711* create new instances of the class and perform a user interaction. But much is still missing. There are no menus and windows typical of a Macintosh application. You can correct this with Application Builder and its System classes. Let’s use your Person class as the foundation of a simple*233* database application.

u Start Prograph from the desktop and select Open… from the File menu. Open the System Classes file. The Classes window opens, with several*421* System class *1048*icons displayed.

*1045*The lines connecting the icons describe*474* inheritance relationships. *771*Inheritance is an object-oriented*0156* feature that allows “parent” classes to pass along their attributes and methods to their “children,” or subclasses*1019*.

Class icons with double hexagonal borders have hidden subclasses. 

u
Click the zoom box in the upper right hand corner of the Classes window to enlarge the window. Click on the Window Item class to select it, and choose*445* Show Classes *644**983*from the Info menu.

Further subclasses  *1020*of the Window Item class are displayed. 

u If necessary, repeat this process, selecting*446* Show Classes *644**984*from the Info menu, until all hidden classes have been displayed.

u
Select Open… from the File menu. Click the*971* Selective Load check box in the file-opening dialog.

u
Double-click on the Person file name in the scrolling list.

u
Double-click on the Person class name in the class list.

u
Prograph loads the Person class into the Classes window. Drag the*424* Person class icon to the upper right corner of the window to set it apart from the larger *1049*System class hierarchy*1046*.

The Selective Load adds the Person class with its attributes and methods to the System classes that are currently in memory. You now have a full set of classes that can ease your development of a full application. 

___________________________________________________________
NOTE: *422**423***919*System classes*1050* are distinguished from user-defined*425* classes by a double line along the bottom edge of their hexagonal icons.
-----------------------------------------------------------

u
Select Save As… from the File menu. Type Folks Database and press Return.

 Overview of Application Builder

*58*The Prograph Development Environment can best be understood in three layers:

In chapter 2, you explored the object-oriented, dataflow, and pictorial nature of the language component of Prograph. You also had a first experience with the class and method editors and used the interpreter. These components, along with the compiler, constitute the environment layer of Prograph.*886*

This chapter presents the important and exciting middle layer of Prograph. Application Builder consists of a collection of high-level editors that organize and facilitate the use of the Prograph System classes.*920*

The Application Builder Application editor*292**38**55* manages instance creation within the*1040* Application*75*, Menu*675*, and Window *1054* system *1177*classes. 

*76**1041*The Application editor*39* *293*serves as a kind of clearing house and a library of menus and windows you can use in your application. The *1051* Menu, Window,*305* *1055**1162*and*309* Window Item *1058**1167*editors are used to specify the “look and feel” of the menus and windows created and organized using the Application editor.*1171**1178*

The Application Builder*300* Menu editor*669* manages the Menu *676*and Menu Item *673**1052*classes.

The Menu editor manages attribute values within instances of the Menu class created using the Application editor. It also manages the instance creation, attribute values, and method associations of instances of the Menu Item *646*class. Associations specified in the Menu editor determine which method executes when a selection is made in a menu of your application.

The Application Builder Window and Window Item editors manage instance creation, attribute values and method associations within the Window*1056**1179*, Window Item classes*1172*, and Window Item *1059*subclasses.

Instances of Window and Window Item are objects. Each has its own behavior. By specifying which methods are executed when various user events occur, you further determine the “look and feel” of your application.

This Grand Tour chapter demonstrates integration of the Application Builder, the language, and the environment of Prograph. All three components work together to facilitate an interactive and efficient evolutionary style of application development.*878*

t
Adding a Menu*568**569*

*19*The first step in creating your database application is to create a menu bar*576*, a menu, and a menu item. At first, your only goal is to make sure that a user can quit your application.

u
Select*276* Edit Application *335**616*from the Exec menu.

Application Builder’s Application editor*40**294* appears as a modal dialog (you must interact with and dismiss it before accessing any other window). The Application editor is command central for managing the creation of menus and windows making up your application.

u
The insertion cursor is flashing in the Name field of the Application editor. Type Folks Database and press Tab.

The insertion cursor moves to theAbout Method *14*field. This field is already filled in with a name, /About, corresponding to a method automatically provided with System Classes.*11* In order to create a brand new “About” method,we will modify this name.

u
Click just after the About name. Type the *315*ellipsis character, “…” (Option-semicolon enters the ellipsis character). The default class when you select the*32* About menu*570* item in the Apple menu of a Prograph application is the Application class. So if you use the *231*data-determined *699*method reference, /About…, Prograph looks for an About… method in the Application class. If you want to put the About… method in any other class, you have to use an *363*explicit-class *704*method reference.

u
Click the Menus radio button. The List of Instances scrolling list displays the name File, corresponding to a File menu supplied with System Classes.

u
Since we want to go through the process of creating a menu from scratch, delete the File menu by selecting it in the List of Instances scrolling list, and click on the Delete button. When the confirmation dialog comes up, click OK.

u
Click the*117* Active List radio button.

u
Double-click the Menu item in the Classes scrolling list (or click Menu, and then click the*116* » New Instance » button below the list) to create a new Menu object. This new instance of class Menu is currently Untitled and is listed in the List of Instances scrolling list.

*295*
u
Double-click the Untitled menu instance*302* to open *671*the*301* Menu editor*670*, or select the Untitled item, and then click the Edit button.

u
Type File to replace the Untitled entry in the Name field and press Tab.

u
The insertion bar moves from the Name field to the Item field. Type Quit and press Tab. The insertion bar moves to the Method field.

u
Type /Quit and press Tab. (The default class of selected menu items is the Menu class. The /Quit method association allows Prograph to use a system-supplied Quit method in the Menu class pool of methods.)

u
The insertion cursor moves to the Key edit field. This field specifies a command key equivalent for the menu item. Type q. The Menu editor looks like the following:

u
Press Return or click the OK button to dismiss the Menu editor.

The Untitled entry in the List of Instances list in the Application editor reads File. Folks Database now consists of a windowless application with a minimal menu. By associating the supplied Quit method in the Menu class with the Quit item in your application’s File menu, Folks Database is already functional.

u
Click OK or press Return to dismiss the Application editor.

u
Select*338* Run initial *619**964*from the*608* Exec menu. In an instant, the Prograph environment menu bar disappears, and the Folks Database application starts running.

u
Though not much to look at yet, Folks Database is functional. It supports quitting. Select Quit from the File menu to leave your application and return to the development environment.

u
Select Run initial from the Exec menu, or use a Command-R key combination, to restart Folks Database.

u
Select About Folks Database… *571*from the*33* Apple menu.

The Folks Database application immediately goes into a suspended state. A dialog pops up informing you that the *12*About… method you specified in the About Method *15* field of the Application editor does not exist.

u
Press Return to continue. Press Select as well in response to the next dialog, which confirms that you want the About… method created in class Application. The menu bar of your application disappears and up pops the development menu bar along with an execution window for an About… method.

___________________________________________________________
NOTE: When you interact with your application in a way that the Prograph interpreter does not understand—for example, if you have not yet written a method you reference in some other method, or if you have assigned an unwritten method name in an edit field of an Application Builder editor—then the development environment pops to the forefront. You are prompted to create or modify the method in question while your application is visible in “suspended animation.” When you have made the necessary additions or corrections, the development environment again fades to the background and your application continues running where it left off. 

This seamless integration between the development environment and your evolving application is at the heart of the fluid programming style encouraged by Prograph’s design. 
-----------------------------------------------------------

u Double-click on the dotted background of the About… execution window to open the editable case window.

u Create a show operation near the center of the About… case window.

___________________________________________________________
NOTE: Remember, to create an operation, Command-click in the case window to place a generic operation icon, and then type the operation’s name and press Return. Or, select an operation from the list of Prograph primitives *914* accessed through the ˙Info… dialog, and select Name from the Transfer pop-up menu. Finally, press Return.

If you have forgotten how to perform basic tasks within the Prograph language, see chapter 2, “The Grand Tour: Language.”
-----------------------------------------------------------

u Double-click on the terminal of the show operation to create a constant. Type This is the Folks Database in Prograph, version 0.1 and press Return.

The default state of any method you *1085*create on the fly while running your application in Prograph is single step and show cases, Step/Show *1006*for short. In this mode, every time the method executes while running your application, the execution window pops up. Successive presses of the Return key advance execution one operation at a time. Double-clicking roots and terminals of executed operations lets you *490*inspect *960* values for the data flowing through connecting datalinks of the method.

Step/Show *621*is normally a desirable default mode for methods during initial development. It lets you check the performance of each operation as you go along. You can, of course, turn Step/Show on or off for any method you desire. Do so when you are in the method case window. Look under the Exec menu to find these menu items. 

The About… method is so simple that you may as well turn*624* Step/Show off so your application can run uninterrupted. When you turn Step/Show off, Step/Show remains in *626*On mode until the current execution of the method is complete. Then it switches to Off mode.

u
With the About… case window active, select Step/Show Off in the Exec menu. Close the case window.

The execution window now shows the About… method as you have just created it. The ready-to-execute highlight is on the input bar.

u
Press Return two times. Execution moves from the input bar to the constant, and then to the show operation. To convince yourself that show is ready to execute, move the pointer over its *1070*terminal and click and hold the mouse button down  to display the data value arriving from the constant operation.  The popup disappears as soon as you let go of the mouse button.  This single-click and hold technique is the fastest method of inspecting data values. 

u
Press Return once more. The execution window is obscured by the show dialog, which displays the Folks Database application and version-number identification.

u
Press Return or click the OK button to dismiss the *13*About… dialog.

u
Execution is now at the output bar. Press Return again. The execution window closes, returning you to your application’s runtime environment, with its two menus, the Apple menu and the File menu.

u
To return to the Prograph development environment, with its menu bar, select Switch Context *575**1029*from the Apple menu.

___________________________________________________________
NOTE: Switch Context*37* is a Prograph term for fluidly jumping back and forth between the Prograph development environment and the application you are creating. The Prograph development environment never really disappears. It remains in the background. 
-----------------------------------------------------------

Now, every time you select About Folks Database… *572*from the*34* Apple menu, the simple dialog defined in the About… method executes. You can also use any Apple Menu items defined in your System Folder. And, of course, you can quit your application.

u
Switch Context, if necessary, to return you to your application’s menu bar. 

u
Select Quit from the File menu to quit the Folks Database application and enter the Prograph development environment.